//
//  StatusCell.swift
//  新浪微博
//
//  Created by MBP on 16/5/18.
//  Copyright © 2016年 MBP. All rights reserved.
//

import UIKit

class StatusCell: UITableViewCell {
    
    //微博视图模型
    var viewModel: StatusViewModel? {
        didSet{
            //作为中转站, 只传递数据
            originalView.viewModel = viewModel
        }
    }

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        //设置cell UI
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //私有控件
    /// 原创微博
    private let originalView: StatusOriginalView = StatusOriginalView()
    /// 被转发微博
    private let retwteedView: StatusRetweetedView = StatusRetweetedView()
    /// 操作栏
    private let toolBarView: StatusToolbar = StatusToolbar()
}

//设置 cell UI
extension StatusCell {
    private func setupUI() {
        //背景颜色
        backgroundColor = UIColor.whiteColor()
        
        //添加控件
        contentView.addSubview(originalView)
        contentView.addSubview(retwteedView)
        contentView.addSubview(toolBarView)
        
        //设置控件的自动布局
        originalView.snp_makeConstraints { (make) in
            make.left.equalTo(contentView)
            make.right.equalTo(contentView)
            make.top.equalTo(contentView)

        }
        
        contentView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self)
            make.right.equalTo(self)
            make.top.equalTo(self)
            
            //使用自动计算行高, 必须给定且只给定一个向下的约束
            make.bottom.equalTo(originalView)

        }
    }
    
}
